<?php
//require('config.php');
require('conectabd/conectame.php');
//require('include/funciones.php');

$tabla="derechohabientes";
if(isset($_GET['campo'])){
$campo=$_GET['campo'];
}
else{
$campo="rfc";
}


if(isset($_GET['q']) and !eregi('^ *$',$_GET['q'])){
        $q = sql_quote($_GET['q']); //para ejecutar consulta
        $busqueda = htmlentities($q); //para mostrar en pantalla

        $sqlStr = "SELECT * FROM ".$tabla." WHERE ".$campo." LIKE '%$q%'";
        $sqlStrAux = "SELECT count(*) as total FROM ".$tabla." WHERE ".$campo." LIKE '%$q%'";
    }else{
        $sqlStr = "SELECT * FROM ".$tabla;
        $sqlStrAux = "SELECT count(*) as total FROM ".$tabla;
    }

$aux = mysql_fetch_assoc(mysql_query($sqlStrAux,$link));
$query = mysql_query($sqlStr, $link);
?>    <p><?php
        if($aux['total'] and isset($busqueda)){
                echo "{$aux['total']} Resultado".($aux['total']>1?'s':'')." que coinciden con:<strong>[ ".$busqueda." ]</strong>";
            }elseif($aux['total'] and !isset($q)){
                echo "Total de registros: {$aux['total']}";
            }elseif(!$aux['total'] and isset($q)){
                echo"No hay registros que coincidan con:<strong>[ ".$busqueda." ]</strong>";
            }
    ?></p>

    <?php 
        if($aux['total']>0){
            echo "<table border='1'>";
            echo "<tr>";
            for($i=0;$i<mysql_num_fields($query);$i++)
                                {
                                   echo "<td>".mysql_field_name($query,$i)."</td>";
                                }
            echo "</tr>";
            $total_campos=mysql_num_fields($query);
            while($row = mysql_fetch_array($query)){
          echo "<tr>";
          for($i=0;$i<$total_campos;$i++){
          echo "<td>".htmlentities($row[$i])."</td>";
                                          }
          echo "</tr>";
          }
           echo "</table>";
        }
    ?> 